package com.registerserver.service;

import java.io.IOException;
import java.lang.reflect.Array;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.Date;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.registerserver.dao.CourseDao;
import com.registerserver.dao.CourseDaoImpl;
import com.registerserver.dao.StudentDao;
import com.registerserver.dao.StudentDaoImpl;
import com.registerserver.dao.StudyingDao;
import com.registerserver.dao.StudyingDaoImpl;
import com.registerserver.dto.CourseRegisteredInfo;
import com.registerserver.dto.SubjectAndMark;
import com.registerserver.model.Course;
import com.registerserver.model.Student;

public class ServiceImpl extends UnicastRemoteObject implements IService {
	CourseDao courseDao;
	StudentDao studentDao;
	StudyingDao studyingDao;
	
	
	public ServiceImpl() throws RemoteException{
		courseDao = new CourseDaoImpl();
		studentDao = new StudentDaoImpl();
		studyingDao = new StudyingDaoImpl();
	}
	
	public Student getStudentInfoByID(String studentID) throws SQLException, IOException,RemoteException {
		Student student = studentDao.getStudentInfoByID(studentID);
		return student;
	} 
	
	public List<CourseRegisteredInfo> getCourseRegisteredInfo(String studentID) throws SQLException,RemoteException{
		String semester = DateFactory.getCurrentSemesterID(); 
		System.out.println(semester+" " + studentID);
		List<CourseRegisteredInfo> list = courseDao.getCoursesInfoRegisteredSInSemester(studentID, semester); 
		return list;
	}

	@Override
	public double getOverAllMarkOfStudent(String studentID)
			throws SQLException, RemoteException {
		double mark = studyingDao.getOverAllMarkOfStudent(studentID);
		return mark;
	}

	@Override
	public int addNewStudying(String subjectID, Course course,
			Student student, Date registerDate, double mark) throws SQLException,
			RemoteException {
		int result = studyingDao.addNewStudying(subjectID, course, student, registerDate, mark);
		return result;
	}

	@Override
	public boolean updateStudying(String subjectID, Course course,
			Student student) throws SQLException, RemoteException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean updateMark(String studentID, String subjectID,
			String courseID) throws SQLException, RemoteException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int deleteStudying(String studentID, String subjectID,
			String courseID) throws SQLException, RemoteException {
		return studyingDao.deleteStudying(studentID, subjectID, courseID); 
	}

	@Override
	public int countStudentRegistered(String courseID, String subjectID) throws SQLException, RemoteException {
		return studyingDao.countStudentRegistered(courseID,subjectID);
	}

	@Override
	public int getMaxSizeOfCourse() throws SQLException, RemoteException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public double getMark() throws SQLException, RemoteException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<SubjectAndMark> getMarkOfAllSubject(String studentID)
			throws SQLException, RemoteException {
		return studyingDao.getMarkOfAllSubject(studentID);
	}
}
